<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8" %>
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700" rel="stylesheet">
    <link rel="stylesheet" href="css/bootstrap.min.css"/>
    <link rel="stylesheet" href="css/fontawesome.css">
    <link rel="stylesheet" href="css/templatemo-style.css">
    <link rel="stylesheet" href="css/owl.css">

    <link rel="stylesheet" type="text/css" href="css/main.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath }/css/bootstrap.min.css"/>

    <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap.js"></script>
    <%--    <link rel="stylesheet" href="css/reset.css">
        <link rel="stylesheet" href="css/car.css">--%>
    <script type="text/javascript">
        function deleteAddr(id) {
            var res = confirm("是否删除");
            if (res == true) {
                window.location.href = "userAddressDel?id=" + id;
            }
        }

        function defaultAddr(id) {
            var res = confirm("是否设为默认");
            if (res == true) {
                window.location.href = "userAddressDef?id=" + id;

            }
        }

        function validate() {
            var addressDetail = $("#addressDetail").val();
            var addressee = $("#addressee").val();
            var addressCellPhone = $("#addressCellPhone").val();
            if (addressDetail == "" || addressee == "" || addressCellPhone == "") {
                alert("收件人、手机号和收货地址不能为空，请填写完整信息");
                return false;
            }
        }

        function validateUpdate() {
            var addressDetailUpdate = $("#addressDetailUpdate").val();
            var addresseeUpdate = $("#addresseeUpdate").val();
            var addressCellPhoneUpdate = $("#addressCellPhoneUpdate").val();
            if (addressDetailUpdate == "" || addresseeUpdate == "" || addressCellPhoneUpdate == "") {
                alert("收件人、手机号和收货地址不能为空，请填写完整信息");
                return false;
            }
        }

    </script>
</head>
<body class="is-preload">

<!-- Wrapper -->
<div id="wrapper" class="">

    <!-- Main -->
    <div id="main">
        <div class="inner">

            <!-- Header -->
            <header id="header">
                <div class="logo">
                    <%--<a href="my.jsp">我的</a>--%>
                </div>
            </header>

            <!-- Banner -->
            <section class="main-banner">
                <div class="container-fluid">
                    <div class="row">
                        <div id="big_right">
                            <div style="margin:0 20px;">
                                <h3>收货地址</h3>
                                <hr>
                                <table class="table table-striped table-hover table-bordered">
                                    <tr>
                                        <th>序号</th>
                                        <th>收件人</th>
                                        <th>手机号</th>
                                        <th>地址</th>
                                        <th>操作</th>
                                    </tr>
                                    <c:forEach var="address" items="${addList}" varStatus="i">
                                        <tr>
                                            <Td>${i.count}</Td>
                                            <td>${address.name}</td>
                                            <td>${address.phone}</td>
                                            <td>${address.detail}</td>
                                            <td>
                                                <button onclick="deleteAddr(${address.id})"
                                                        class="btn btn-danger btn-sm">删除
                                                </button>&nbsp;&nbsp;
                                                <button class="btn btn-default btn-sm" data-toggle="modal"
                                                        data-target="#myModal${address.id}">修改
                                                </button>&nbsp;&nbsp;
                                                <!-- 弹出模态框 -->
                                                <div class="modal fade" tabindex="-1" role="dialog"
                                                     id="myModal${address.id}">
                                                    <div class="modal-dialog" role="document">
                                                        <div class="modal-content">
                                                            <div class="modal-header">
                                                                <button type="button" class="close"
                                                                        data-dismiss="modal">
                                                                    <span>&times;</span>
                                                                </button>
                                                                <h4 class="modal-title">修改地址</h4>
                                                            </div>
                                                            <form action="useraddressupdate" method="post"
                                                                  class="form-horizontal" onsubmit="return validateUpdate()">
                                                                <div class="motal-body">
                                                                    <div class="form-group">
                                                                        <label class="col-sm-2 control-label">收件人</label>
                                                                        <div class="col-sm-10">
                                                                            <input type="hidden" name="id"
                                                                                   value="${address.id}">
                                                                            <input id="addressDetailUpdate" type="text" name="name"
                                                                                   class="form-control"
                                                                                   value="${address.name}">
                                                                        </div>
                                                                    </div>
                                                                    <div class="form-group">
                                                                        <label class="col-sm-2 control-label">电话</label>
                                                                        <div class="col-sm-10">
                                                                            <input id="addresseeUpdate" type="text" name="phone"
                                                                                   class="form-control"
                                                                                   value="${address.phone}">
                                                                        </div>
                                                                    </div>
                                                                    <div class="form-group">
                                                                        <label class="col-sm-2 control-label">详细地址</label>
                                                                        <div class="col-sm-10">
                                                                            <input id="addressCellPhoneUpdate" type="text" name="detail"
                                                                                   class="form-control"
                                                                                   value="${address.detail}">
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                                <div class="motal-footer">
                                                                    <button type="submit" class="btn btn-primary">修改
                                                                    </button>
                                                                </div>
                                                            </form>
                                                        </div>
                                                    </div>
                                                </div>
                                                <button onclick="defaultAddr(${address.id})"
                                                        class="btn btn-primary btn-sm">设为默认
                                                </button>
                                                <c:if test="${address.flag==3}">
                                                    <span class="badge" style="background-color:red;">默认</span>
                                                </c:if>
                                                <c:if test="${address.flag==1}">
                                                    <span class="badge">普通</span>
                                                </c:if>
                                            </td>
                                        </tr>
                                    </c:forEach>
                                </table>
                            </div>
                            <br>
                            <div  style="margin:0 20px;">
                                <form action="userAddressAdd" method="post" class="form-horizontal"
                                      onsubmit="return validate()">
                                    <div class="form-group">
                                        <label class="col-sm-2 form-label">收件人</label>
                                        <div class="col-sm-3">
                                            <input id="addressee" type="text" class="form-control" name="name"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 form-label">手机号</label>
                                        <div class="col-sm-3">
                                            <input id="addressCellPhone" type="text" class="form-control" name="phone"/>
                                        </div>
                                    </div>
                                    <div class="" style="margin-bottom: 8px">
                                        <label class="form-label">详细地址</label>
                                        <textarea id="addressDetail" rows="3" class="form-control"
                                                  name="detail"></textarea>
                                    </div>
                                    <div class=" col-md-12">
                                        <input type="submit" class="btn btn-primary" value="添加地址">
                                        <a target=_parent href="${pageContext.request.contextPath}/getCart"
                                           class="btn btn-primary">返回购物车</a>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </section>


        </div>
    </div>

    <!-- Sidebar -->
    <div id="sidebar">

        <div class="inner">


            <!-- Menu -->
            <nav id="menu">
                <ul>
                    <p style="font-size:18px">个人中心</p>
                    <li><a href="myList_info.jsp">我的个人中心</a></li>
                    <li><a href="">消息通知</a></li>
                    <li><a href="userAddressShow">收货地址</a></li>
                    <li><a href="https://www.google.com">优惠券</a></li>
                    <p style="font-size:18px">订单中心</p>
                    <li><a href="getOrderList">我的订单</a></li>
                    <li><a href="">意外保</a></li>
                    <li><a href="">团购订单</a></li>
                    <li><a href="">评价晒单</a></li>
                </ul>
            </nav>


        </div>
    </div>

</div>

</body>
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.bundle.min.js"></script>

<script src="js/browser.min.js"></script>
<script src="js/breakpoints.min.js"></script>
<script src="js/transition.js"></script>
<script src="js/owl-carousel.js"></script>
<script src="js/custom.js"></script>
</html>